unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, BaseGrid, AdvGrid, RzButton, ExtCtrls, RzPanel, frxClass,
  frxPreview, frxDesgn,frxEngine;

type
  TForm1 = class(TForm)
    RzToolbar1: TRzToolbar;
    RzToolButton1: TRzToolButton;
    RzToolButton2: TRzToolButton;
    RzToolButton3: TRzToolButton;
    AdvGrid1: TAdvStringGrid;
    frxReport1: TfrxReport;
    frxUserDataSet1: TfrxUserDataSet;
    frxDesigner1: TfrxDesigner;
    procedure FormShow(Sender: TObject);
    procedure RzToolButton1Click(Sender: TObject);
    procedure frxUserDataSet1GetValue(const VarName: string;
      var Value: Variant);
    procedure RzToolButton2Click(Sender: TObject);
    procedure RzToolButton3Click(Sender: TObject);
    procedure frxReport1BeforePrint(Sender: TfrxReportComponent);
  private
    { Private declarations }
  public
    procedure SetGridParams;
    procedure OnKzPrintGetCellStyl(var C:TfrxView);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.FormShow(Sender: TObject);
begin
  SetGridParams;
end;

procedure TForm1.frxReport1BeforePrint(Sender: TfrxReportComponent);
var
  I:Integer;
begin
  for I := 0 to frxReport1.ComponentCount - 1 do
  begin
    if frxReport1.Components[I] is TfrxView then
    begin
      TfrxView(frxReport1.Components[I]).FOnKzPrintGetCellStyl:=OnKzPrintGetCellStyl;
    end;
  end;
end;

procedure TForm1.frxUserDataSet1GetValue(const VarName: string;
  var Value: Variant);
var
  I:Integer;
  TempA:string;
begin
  for I := 0 to 9  do
  begin
    TempA:=Format('Field%D',[I]);
    if VarName=TempA then Value:=AdvGrid1.Cells[I,frxUserDataSet1.RecNo];

  end;
end;

procedure TForm1.OnKzPrintGetCellStyl(var C: TfrxView);
begin
  if (C.FCol=1)  and (C.FRow=1) then
  begin
    C.Font.Color:=clRed;
  end else
  if (C.FCol=2) and (C.FRow=2) then
  begin
    TfrxMemoView(C).HAlign:=frxClass.haCenter;
  end;
end;

procedure TForm1.RzToolButton1Click(Sender: TObject);
begin
  frxUserDataSet1.RangeEnd:=reCount;
  frxUserDataSet1.RangeEndCount:=AdvGrid1.RowCount;

  frxReport1.ShowReport();
end;

procedure TForm1.RzToolButton2Click(Sender: TObject);
begin
  frxReport1.DesignReport();
end;

procedure TForm1.RzToolButton3Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.SetGridParams;
var
  I,M:Integer;
begin
  with AdvGrid1 do
  begin
    DefaultColWidth:=100;
    ColCount:=10;
    RowCount:=10;

    for I := 0 to ColCount - 1 do
    begin
      for M := 0 to RowCount - 1 do
      begin
        Cells[I,M]:=Format('Text:%D|%D',[I,M]);
      end;
    end;
  end;
end;

end.
